from app import db
class UserInfo(db.Model):
    __tablename__ = 'user_info'

    user_id = db.Column(db.String(255), db.ForeignKey('users.id'), primary_key=True)
    full_name = db.Column(db.String(255))
    birth_date = db.Column(db.DateTime)
    gender = db.Column(db.String(20))
    location = db.Column(db.String(255))
    occupation = db.Column(db.String(255))
    bio = db.Column(db.Text)
    interests = db.Column(db.Text)
    education = db.Column(db.String(255))
    skills = db.Column(db.String(255))
    achievements = db.Column(db.Text)
    social_media = db.Column(db.Text)
    recent_activities = db.Column(db.Text)
    phone = db.Column(db.String(50))
    email = db.Column(db.String(255))
    avatar = db.Column(db.String(255))

    # 建立与 User 模型的一对一关系（假设每个用户只有一条详细信息记录）
    user = db.relationship('User', backref=db.backref('user_info', uselist=False))

    def __repr__(self):
        return f"<UserInfo(user_id='{self.user_id}', full_name='{self.full_name}')>"

    def to_dict(self):
        return {
            "user_id": self.user_id,
            "full_name": self.full_name,
            "birth_date": self.birth_date.strftime("%Y-%m-%d") if self.birth_date else None,
            "gender": self.gender,
            "location": self.location,
            "occupation": self.occupation,
            "bio": self.bio,
            "interests": self.interests,  # 如果存的是 JSON 字符串，可先使用 json.loads() 转换
            "education": self.education,
            "skills": self.skills,
            "achievements": self.achievements,
            "social_media": self.social_media,
            "recent_activities": self.recent_activities,
            "phone": self.phone,
            "email": self.email,
            "avatar": self.avatar,
        }
